{% extends 'food/base.html' %}

{% block content %}
<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5 class="mb-0">食品管理</h5>
        <a href="{% url 'admin:food_food_add' %}" class="btn btn-primary btn-sm">添加食品</a>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>名称</th>
                        <th>类别</th>
                        <th>数量</th>
                        <th>存储位置</th>
                        <th>保质期</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for food in foods %}
                    <tr>
                        <td>{{ food.name }}</td>
                        <td>{{ food.category.name }}</td>
                        <td>{{ food.quantity }} {{ food.unit }}</td>
                        <td>{{ food.storage_location }}</td>
                        <td>{{ food.expiry_date }}</td>
                        <td>
                            <a href="{% url 'food:food_detail' food.id %}" class="btn btn-sm btn-info">查看</a>
                            <a href="{% url 'admin:food_food_change' food.id %}" class="btn btn-sm btn-primary">编辑</a>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="6" class="text-center">暂无食品数据</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
